package com.sys.controller;

import com.sys.service.PaymentHystrixService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
//@DefaultProperties(defaultFallback = "orderInfo_TimeOutHandle_Global")
public class OrderHystrixController {

    @Resource
    private PaymentHystrixService paymentHystrixService;

    // http://localhost/consumer/order/hystrix/ok/1
    @GetMapping("/consumer/order/hystrix/ok/{id}")
    public String orderInfo_OK(@PathVariable("id") Integer id) {
        String result = paymentHystrixService.paymentInfo_OK(id);
        return result;
    }

    // http://localhost/consumer/order/hystrix/timeout/1
    @GetMapping("/consumer/order/hystrix/timeout/{id}")
    /*@HystrixCommand(fallbackMethod = "orderInfo_TimeOutHandle", commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "6000")
    })*/
    //@HystrixCommand
    public String orderInfo_TimeOut(@PathVariable("id") Integer id) {
        //int exception = 10 / 0;
        String result = paymentHystrixService.paymentInfo_TimeOut(id);
        return result;
    }

    public String orderInfo_TimeOutHandle(@PathVariable("id") Integer id) {
        return "线程池：" + Thread.currentThread().getName() + " 降级方法";
    }

    public String orderInfo_TimeOutHandle_Global(){
        return "全局fallback方法";
    }

}
